
#pragma once

#ifdef _FAN_FAN_
#include "VARBinary.h"
#include "LinkedList.h"
#include "Utility.h"
#include "CodeAcquire.h"
#include "Serialize.h"

class CUploadNode : public CLinkedNode
{
public:
	CUploadNode(intptr_t tp) :dataType(tp) {}
	intptr_t getDataType() { return dataType; }
protected:
	intptr_t dataType;	//0-text 1-jpg 2-msg
};


class CUploadList :public CLinkedList
{
public:
	CUploadNode *GetNode() override
	{
		return (CUploadNode *)CLinkedList::GetNode();
	}
};


class CUploadText : public CUploadNode
{
public:
	CUploadText(LPCSTR bidno, LPCWSTR t) :CUploadNode(0), bidNumber(bidno), text(t) { time(&logTime); }
	~CUploadText() override
	{
		if (bidNumber) HeapFree(GetProcessHeap(), 0, (LPVOID)bidNumber);
		if (text) HeapFree(GetProcessHeap(), 0, (LPVOID)text);
	}
	__forceinline const time_t *getLogTime() { return &logTime; }
	__forceinline LPCSTR getBidNumber() { return bidNumber; }
	__forceinline LPCWSTR getText() { return text; }
protected:
	time_t logTime;
	LPCSTR bidNumber;
	LPCWSTR text;
};

class CUploadPic : public CUploadNode
{
public:
	CUploadPic(const CVARBinary &v) :CUploadNode(1) { code.set(v); }
	CVARBinary &getCode() { return code; }
protected:
	CVARBinary code;
};

class CUploadMsg :public CUploadNode, public ISerialize
{
public:
	CUploadMsg() :CUploadNode(2) {}
	virtual CVARBinary *getData() = 0;
protected:
	LPCSTR cvString(LPCSTR v, bool isUTF8)
	{
		if (!isUTF8) return v;
		LPCSTR va = UTF8toANSI(v); if (v) HeapFree(GetProcessHeap(), 0, (LPVOID)v);
		return va;
	}
};

#ifndef _WEBKIT_NEW
class CParamSys_AddLineRsp;
class CWebPacket;
#else
class CJSONMsg;
class CParamDEST_BidUpdate;
#endif
class CUploadMsg22 : public CUploadMsg
{
public:
	~CUploadMsg22() override;
	CVARBinary *getData() override;

	CUploadMsg22(CVARBinary&v);
	//ISerialize
	bool writeTo(CVARBinary &bin) override;
	bool readFrom(CVARBinary &bin) override;
	size_t serialSize() override;
protected:
	struct {
		cst_tickTime_Now nowTime;
		char ip[20];
		bool isSpecial;
		intptr_t myProg, nowProg;
	} data;
	LPCSTR requestid, bidnumber, bidamount, bidtime, servertime, msg, responsecode, responsemsg;
#ifndef _WEBKIT_NEW
public:
	CUploadMsg22(const CWebPacket *pPacket, const CParamSys_AddLineRsp *pParam, const cst_tickTime_Now &tm, LPCSTR &f_bidtime, LPCSTR &f_msg
#ifdef _SECKILL
		, intptr_t myprog, intptr_t nowprog
#endif
	);
#else
public:
	CUploadMsg22(const CJSONMsg &msg, const CParamDEST_BidUpdate *pParam, const cst_tickTime_Now &tm, LPCSTR bidno, LPCWSTR bidtm);
#endif
};

#ifndef _WEBKIT_NEW
class CParamSys_CommitRsp;
class CParamQuery_Commit;
#endif
class CUploadMsg23 : public CUploadMsg
{
public:
	~CUploadMsg23() override;
	CVARBinary *getData() override;

	CUploadMsg23(CVARBinary&v);
	//ISerialize
	bool writeTo(CVARBinary &bin) override;
	bool readFrom(CVARBinary &bin) override;
	size_t serialSize() override;
protected:
	struct {
		cst_tickTime_Now nowTime;
		char ip[20];
		bool isSpecial;
	} data;
	LPCSTR requestid, bidnumber, bidamount, bidtime, dealtime, servertime, responsecode, msg;
#ifndef _WEBKIT_NEW
public:
	CUploadMsg23(const CWebPacket *pPacket, const CParamSys_CommitRsp *pParam, const cst_tickTime_Now &tm, LPCSTR &f_bidtime, LPCSTR &f_dealtime);
	CUploadMsg23(LPCSTR pBody, const CParamQuery_Commit *pParam, const cst_tickTime_Now &tm);
#else
public:
	CUploadMsg23(const CJSONMsg &msg, const CParamDEST_BidUpdate *pParam, const cst_tickTime_Now &tm, LPCSTR bidno, LPCWSTR bidtm, LPCWSTR dealtm);
#endif
};

#ifndef _WEBKIT_NEW
class CParamSys_ResultRsp;
#else
class CParamDEST_Message;
#endif
class CUploadMsg32 : public CUploadMsg
{
public:
	~CUploadMsg32() override;
	CVARBinary *getData() override;

	CUploadMsg32(CVARBinary&v);
	//ISerialize
	bool writeTo(CVARBinary &bin) override;
	bool readFrom(CVARBinary &bin) override;
	size_t serialSize() override;
	__forceinline LPCSTR getMsgdata() const { return msgdata; }
protected:
	struct {
		cst_tickTime_Now nowTime;
		char ip[20];
	} data;
	LPCSTR bidnumber, responsecode, responsemsg, msgdata;
#ifndef _WEBKIT_NEW
public:
	CUploadMsg32(const CWebPacket *pPacket, const CParamSys_ResultRsp *pParam, const cst_tickTime_Now &tm);
#else
public:
	CUploadMsg32(const CJSONMsg &msg, const CParamDEST_Message *pParam, const cst_tickTime_Now &tm, LPCSTR bidno);
#endif
};

class CUploadAcqRec : public CUploadMsg
{
public:
	CUploadAcqRec(LPCSTR _codeid, CCodeAcquire::Source _source, CCodeAcquire::Oper _oper,
		LPCSTR _answer, intptr_t _weight, LPCSTR _msg, const cst_tickTime_Now &tm);
	~CUploadAcqRec() override;
	CVARBinary *getData() override;

	CUploadAcqRec(CVARBinary&v);
	//ISerialize
	bool writeTo(CVARBinary &bin) override;
	bool readFrom(CVARBinary &bin) override;
	size_t serialSize() override;
protected:
	struct {
		CCodeAcquire::Source source;
		CCodeAcquire::Oper oper;
		intptr_t weight;
		cst_tickTime_Now nowTime;
	} data;
	LPCSTR codeid, answer, msg;
};


#endif	//_FAN_FAN_
